$(document).ready(function(){
	$("#btn_connect").click(function(){
		$.xmpp.connect({
			onMessage: function(message){
				if(message.body != undefined){
					console.log("Msg Rec: "+message.body);	
				}
			},
			onPresence: function(presence){
				// Handle subscriptions
				console.log(presence.toXML);
				if(presence.type != undefined){
					if(presence.type == "subscribe"){
						// Eventually pop up a message to ask to accept a "friend request" or to be subscribed to.
						// Just accept the subscription for now
						$.xmpp.subscribeToPresence(presence.from, true);
					}else if(presence.type == "unsubscribe"){
						// Not sure what to do here yet..
					}
				}
			},
			onIq: function(iq){
				console.log(iq);
			}
		});
		//$.xmpp.setPresence();
	});
	
	$("#presence").change(function(){
		var presence;
		if($("#presence").val() != "online"){
			presence = $("#presence").val();
		}
		
		$.xmpp.setPresence(presence);
	});
	
	$("#btn_sendMessage").click(function(){
		var options = {
			to: $("#to").val(),
			body: $("#body").val(),
			resource: $("#resource").val()
		}
		
		$.xmpp.sendMessage(options);
	});
	
	$("#btn_disconnect").click(function(){
		$.xmpp.disconnect();
	});
});
